package com.ruoyi.web.controller.config;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.config.VsAreaCode;
import com.ruoyi.system.service.config.IVsAreaCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * 国际区号Controller
 * 
 * @author zzx
 * @date 2024-05-27
 */
@Api(tags = "国际区号")
@RestController
@RequestMapping("/config/code")
public class VsAreaCodeController extends BaseController
{
    @Autowired
    private IVsAreaCodeService vsAreaCodeService;

    /**
     * 查询国际区号列表
     */
    @ApiOperation("查询国际区号列表")
    @GetMapping("/list")
    public TableDataInfo list(VsAreaCode vsAreaCode)
    {
//        startPage();
        List<VsAreaCode> list = vsAreaCodeService.selectVsAreaCodeList(vsAreaCode);
        return getDataTable(list);
    }

    /**
     *
     * 导出国际区号列表
     */
//    @ApiOperation("导出国际区号列表")
    @Log(title = "国际区号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VsAreaCode vsAreaCode)
    {
        List<VsAreaCode> list = vsAreaCodeService.selectVsAreaCodeList(vsAreaCode);
        ExcelUtil<VsAreaCode> util = new ExcelUtil<VsAreaCode>(VsAreaCode.class);
        util.exportExcel(response, list, "国际区号数据");
    }

    /**
     * 获取国际区号详细信息
     */
//    @ApiOperation("获取国际区号详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vsAreaCodeService.selectVsAreaCodeById(id));
    }

    /**
     * 新增国际区号
     */
//    @ApiOperation("新增国际区号")
    @Log(title = "国际区号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsAreaCode vsAreaCode)
    {
        return toAjax(vsAreaCodeService.insertVsAreaCode(vsAreaCode));
    }

    /**
     * 修改国际区号
     */
//    @ApiOperation("修改国际区号")
    @Log(title = "国际区号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsAreaCode vsAreaCode)
    {
        return toAjax(vsAreaCodeService.updateVsAreaCode(vsAreaCode));
    }

    /**
     * 删除国际区号
     */
//    @ApiOperation("删除国际区号")
    @Log(title = "国际区号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vsAreaCodeService.deleteVsAreaCodeByIds(ids));
    }

    @PostMapping("/translateAreaCode")
    public AjaxResult translateAreaCode(@RequestBody VsAreaCode vsAreaCode)
    {
        List<VsAreaCode> list = vsAreaCodeService.selectVsAreaCodeList(vsAreaCode);
    	return success(vsAreaCodeService.translateAreaCode(list));
    }

}
